package com.springboot.frame.oauth.server.security.hadler;

import com.springboot.frame.oauth.server.utils.ResponseUtils;
import com.springboot.frame.oauth.server.utils.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 未授权用户访问无权限时的处理
 *
 * @author lirong
 * @date 2019-8-8 17:37:27
 */
@Component
@Slf4j
public class SecurityAuthenticationEntryPoint implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
        ResponseUtils.renderJson(response, ResultCode.UNAUTHORIZED);
    }
}
